package com.xysl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xysl.api.domain.Advertisement;
import com.xysl.api.domain.AdvertisementAnnex;
import com.xysl.domain.dto.AdvertisementDTO;
import com.xysl.mapper.XyslAdvAnnexMapper;
import com.xysl.mapper.XyslAdvertisementMapper;
import com.xysl.service.AdvertisementService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AdvertisementServiceImpl implements AdvertisementService {


    @Resource
    XyslAdvertisementMapper advMapper;

    @Resource
    XyslAdvAnnexMapper advAnnexMapper;

    /**
     * 查询首页 广告数据
     * @return
     */
    @Override
    public List<Advertisement> queryAdvList(AdvertisementDTO param) {
        LambdaQueryWrapper<Advertisement> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Advertisement::getStatus,1);
        wrapper.eq(Advertisement::getAdvPosition,1);
        wrapper.orderByAsc(Advertisement::getAdvSort);
        List<Advertisement> list = advMapper.selectList(wrapper);
        for (Advertisement adv : list) {
            LambdaQueryWrapper<AdvertisementAnnex> wr = new LambdaQueryWrapper<>();
            wr.eq(AdvertisementAnnex::getAdvId,adv.getId());
            adv.setAnnexes(advAnnexMapper.selectList(wr));
        }
        return list;
    }
}
